/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.yuhanginfo.modules.sys.web;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.google.common.collect.Lists;
import com.yuhanginfo.common.persistence.Page;
import com.yuhanginfo.common.utils.StringUtils;
import com.yuhanginfo.common.utils.excel.ExportExcel;
import com.yuhanginfo.common.web.BaseController;
import com.yuhanginfo.modules.sys.entity.Area;
import com.yuhanginfo.modules.sys.entity.Credit;
import com.yuhanginfo.modules.sys.entity.InvoiceInfo;
import com.yuhanginfo.modules.sys.entity.PayHistory;
import com.yuhanginfo.modules.sys.entity.Store;
import com.yuhanginfo.modules.sys.entity.StoreArea;
import com.yuhanginfo.modules.sys.entity.TransactionHistory;
import com.yuhanginfo.modules.sys.entity.User;
import com.yuhanginfo.modules.sys.entity.UserEditHistroy;
import com.yuhanginfo.modules.sys.entity.UserStore;
import com.yuhanginfo.modules.sys.entity.YongUser;
import com.yuhanginfo.modules.sys.service.AreaService;
import com.yuhanginfo.modules.sys.service.CreditService;
import com.yuhanginfo.modules.sys.service.InvoiceInfoService;
import com.yuhanginfo.modules.sys.service.PayHistoryService;
import com.yuhanginfo.modules.sys.service.StoreService;
import com.yuhanginfo.modules.sys.service.SysUserStoreService;
import com.yuhanginfo.modules.sys.service.SystemService;
import com.yuhanginfo.modules.sys.service.TransactionHistoryService;
import com.yuhanginfo.modules.sys.service.UserEditHistroyService;
import com.yuhanginfo.modules.sys.service.UserStoreService;
import com.yuhanginfo.modules.sys.service.YongUserService;
import com.yuhanginfo.modules.sys.utils.CodeUtil;
import com.yuhanginfo.modules.sys.utils.UserUtils;


/**
 * 用户管理Controller
 * @author lvls
 * @version 2017-09-18
 */
@Controller
@RequestMapping(value = "${adminPath}/sys/commonUser")
public class CommonUserController extends BaseController {

	private static final Logger logger = LoggerFactory.getLogger(CommonUserController.class);
	
	@Autowired
	private YongUserService yongUserService;
	
	@Autowired
	private AreaService areaService;
	
	@Autowired
	private StoreService storeService;
	
	@Autowired
	private SysUserStoreService sysUserStoreService;
	
	@Autowired
	private SystemService systemService;
	
	@Autowired
	private UserEditHistroyService userEditHistroyService;
	
	@Autowired
	private CreditService creditService;
	
	@Autowired
	private TransactionHistoryService transactionHistoryService;
	
	@Autowired
	private InvoiceInfoService invoiceInfoService;
	
	@Autowired
	private UserStoreService userStoreService;
	
	@Autowired
	private PayHistoryService payHistoryService;
	
	private static final String REDIRECT = "redirect:";
	
	private static final String LINK = "/sys/commonUser/?repage";
	
	private static final String LINK2 = "/sys/commonUser/creditLine?id=";
	
	private static final String LINK3 = "/sys/commonUser/transactionHistoryShow?userId=";
	
	private static final String TIPS = "该用户还没有信用额度，无法进行操作";
	
	private static final String PROVINCE = "province";
	
	private static final String INVOICEINFO = "invoiceInfo";
	
	@ModelAttribute
	public YongUser get(@RequestParam(required=false) String id) {
		YongUser entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = yongUserService.get(id);
		}
		if (entity == null){
			entity = new YongUser();
		}
		return entity;
	}
	/************************************普通用户管理*********************************/
	@RequiresPermissions("sys:commonUser:view")
	@RequestMapping(value = {"list", ""})
	public String list(YongUser user, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<YongUser> page = yongUserService.selectCommonUser(new Page<YongUser>(request, response), user); 
		model.addAttribute("page", page);
		model.addAttribute("user", user);
		return "modules/sys/yonguser/userList";
	}
    
	@RequiresPermissions("sys:commonUser:edit")
	@RequestMapping(value = "save")
	public String save(YongUser user, Model model, RedirectAttributes redirectAttributes) {
		yongUserService.save(user);
		addMessage(redirectAttributes, "保存用户信息成功");
		return REDIRECT + adminPath + LINK;
	}
	
	@RequiresPermissions("sys:commonUser:view")
    @RequestMapping(value = "export")
    public String export(HttpServletRequest request, HttpServletResponse response,YongUser user, RedirectAttributes redirectAttributes) {
		Page<YongUser> selectCommonUser = yongUserService.selectCommonUser(new Page<YongUser>(request, response), user);
		List<YongUser> users = selectCommonUser.getList();
		try {
			String fileName = "极配正品普通用户信息.xlsx";
			new ExportExcel("极配正品普通用户信息", YongUser.class, 2).setDataList(users).write(response, fileName).dispose();
			return null;
		} catch (Exception e) {
			logger.info("export",e);
			addMessage(redirectAttributes, "信息导出失败！失败信息："+e.getMessage());
		}
		return REDIRECT+ adminPath +LINK;
    }
	
	/************************************会员用户审核*********************************/
	@RequiresPermissions("sys:commonUser:view")
	@RequestMapping(value = "vipUserList")
	public String vipUserList(YongUser user, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<YongUser> page = yongUserService.selectVipUser(new Page<YongUser>(request, response), user); 
		List<Area> province=areaService.selectProvinceList();
		model.addAttribute("page", page);
		model.addAttribute("user", user);
		model.addAttribute(PROVINCE, province);
		return "modules/sys/yonguser/vipUserList";
	}
	
	@RequiresPermissions("sys:commonUser:view")
	@RequestMapping(value = "companyDetail")
	public String companyDetail(YongUser user, HttpServletRequest request, HttpServletResponse response, Model model) {
		YongUser resultUser = yongUserService.get(user.getId());
		model.addAttribute("user", resultUser);
		return "modules/sys/yonguser/companyDetail";
	}
	
	@RequiresPermissions("sys:commonUser:view")
	@RequestMapping(value = "companyAuditing")
	public String companyAuditing(YongUser user, HttpServletRequest request, HttpServletResponse response, Model model) {
		YongUser resultUser = yongUserService.get(user.getId());
		model.addAttribute("user", resultUser);
		return "modules/sys/yonguser/companyAuditing";
	}
	
	@RequiresPermissions("sys:commonUser:view")
	@RequestMapping(value = "companyAuditingPass")
	public String companyAuditingPass(YongUser user, HttpServletRequest request, HttpServletResponse response, Model model,RedirectAttributes redirectAttributes) {
		YongUser yongUser = yongUserService.get(user.getId());
		String examineState = user.getExamineState();
		if("2".equals(examineState)){
			yongUser.setExamineState("2");
			yongUser.setUserType("2");
			//审核通过后给会员新增一条信用额度记录
			Credit credit = new Credit();
			credit.setUserId(yongUser.getId());
			credit.setMoney(BigDecimal.valueOf(0, 2));
			credit.setRechargeMoney(BigDecimal.valueOf(0, 2));
			credit.setUseMoney(BigDecimal.valueOf(0, 2));
			credit.setStatus(1);
			creditService.save(credit);
		}else{
			yongUser.setExamineState("3");
			yongUser.setRemark(user.getRemark());
		}
		yongUserService.save(yongUser);
		addMessage(redirectAttributes, "保存用户信息成功");
		return REDIRECT+ adminPath +"/sys/commonUser/vipUserList";
	}
	
	/************************************会员信息设置*********************************/
	@RequiresPermissions("sys:commonUser:view")
	@RequestMapping(value = "vipUserInfoList")
	public String vipUserInfoList(YongUser user, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<YongUser> page = yongUserService.vipUserInfoList(new Page<YongUser>(request, response), user); 
		List<Area> province=areaService.selectProvinceList();
		model.addAttribute("page", page);
		model.addAttribute("province", province);
		model.addAttribute("user", user);
		return "modules/sys/yonguser/vipUserInfoList";
	}
	
	@RequiresPermissions("sys:commonUser:view")
	@RequestMapping(value = "vipUserInfoStore")
	public String vipUserInfoStore(YongUser yongUser, HttpServletRequest request, HttpServletResponse response, Model model) {
		User sysUser = UserUtils.getUser();
		List<Area> province=areaService.selectProvinceList();
		//获取登录用户可选择的门店
		List<String> sysUserStoresCode = sysUserStoreService.selectStoreBySysUserId(sysUser.getId());
		List<Store> sysUserStores = storeService.selectByCodes(sysUserStoresCode);
		//获取用户对应的所有下单门店
		List<String> userStoresCode = userStoreService.selectUserStoreCodeByUserId(yongUser.getId());
		List<Store> userStores = new ArrayList<>();
		if(!userStoresCode.isEmpty()){
			userStores = storeService.selectByCodes(userStoresCode);
		}
		yongUser.setStoreList(userStores);
		//显示用户所属业务员
		String beSysUserId = yongUser.getBeSysUserId();
		User sala = new User();
		if(beSysUserId!=null){
			sala = systemService.getUser(beSysUserId);
		}
		//显示用户操作记录
		UserEditHistroy userEditHistroy = new UserEditHistroy();
		userEditHistroy.setUserId(yongUser.getId());
		Page<UserEditHistroy> pageUserEditHistroys = userEditHistroyService.selectUserEditHistroyOnStoreByUserId(new Page<UserEditHistroy>(request, response),userEditHistroy);
		model.addAttribute("yongUser", yongUser);
		model.addAttribute("sala", sala);
		model.addAttribute("page", pageUserEditHistroys);
		model.addAttribute("sysUserStores", sysUserStores);
		model.addAttribute("province", province);
		return "modules/sys/yonguser/vipUserInfoStore";
	}
	
	@RequiresPermissions("sys:commonUser:view")
	@RequestMapping(value = "saveVipUserInfoStore")
	public String saveVipUserInfoStore(YongUser user,String storeList, HttpServletRequest request, HttpServletResponse response, Model model,RedirectAttributes redirectAttributes) {
		Store beStoreCode = storeService.selectByCode(user.getBeStoreCode());
		StringBuilder orderStoreCode = new StringBuilder();
		StringBuilder orderStoreCnName = new StringBuilder();
		List<String> beStoreCodes = new ArrayList<>();
		//保存门店信息
		if(user.getStoreIdList().size()>0) {
			List<Store> storeList1 = Lists.newArrayList();
			for(String storeId:user.getStoreIdList()) {
				if(StringUtils.isNotEmpty(storeId)) {
					Store s=systemService.findStoreById(storeId);
					orderStoreCode.append(s.getCode()+";");
					orderStoreCnName.append(s.getCnName()+";");
					beStoreCodes.add(s.getCode());
					storeList1.add(s);
				}
			}
			user.setStoreList(storeList1);
		}
		//查询出数据库中该用户对用的下单门店数据
		List<UserStore> oldUserStores = userStoreService.selectUserStoreByUserId(user.getId());
		for (UserStore oldUserStore : oldUserStores) {
			//如果数据库中下单门店不在此次选择的下单门店中，则删除该记录
			String code = oldUserStore.getStoreCode();
			if(!beStoreCodes.contains(code)){
				userStoreService.delete(oldUserStore);
			}
		}
		orderStoreCode.deleteCharAt(orderStoreCode.length()-1);
		orderStoreCnName.deleteCharAt(orderStoreCnName.length()-1);
		if(user.getStoreList() != null && user.getStoreList().size() > 0) {
			for(Store s:user.getStoreList()) {
				UserStore sus=new UserStore();
				sus.setStoreCode(s.getCode());
				sus.setUserId(user.getId());
				sus.setCreateBy(UserUtils.getUser());
				sus.setDelFlag("0");
				sus.setUpdateBy(UserUtils.getUser());
				sus.setUpdateDate(new Date());
				sus.setCreateDate(new Date());
				userStoreService.save(sus);
			}
		}
		yongUserService.save(user);
		//新增一条会员操作历史记录
		UserEditHistroy userEditHistroy = new UserEditHistroy();
		userEditHistroy.setUserId(user.getId());
		userEditHistroy.setSysUserId(user.getBeSysUserId());
		userEditHistroy.setBeStoreCode(user.getBeStoreCode());
		userEditHistroy.setBeStoreCnName(beStoreCode.getCnName());
		userEditHistroy.setDiscount(user.getDiscount());
		userEditHistroy.setOrderStoreCode(orderStoreCode.toString());
		userEditHistroy.setOrderStoreCnName(orderStoreCnName.toString());
		userEditHistroyService.save(userEditHistroy);
		addMessage(redirectAttributes, "保存会员信息成功");
		return REDIRECT+ adminPath +"/sys/commonUser/vipUserInfoList";
	}
	
	@RequiresPermissions("sys:commonUser:view")
	@RequestMapping(value = "selectSaleByStore")
	@ResponseBody
	public List<User> selectSaleByStore(Store store, HttpServletRequest request, HttpServletResponse response, Model model) {
		List<User> users = new ArrayList<>();
		if(store.getCode()!=null &&store.getCode()!=""){
			users = storeService.selectSaleByStore(store);
		}
		return users;
	}
	
	@RequiresPermissions("sys:commonUser:view")
	@RequestMapping(value = "selectAllStoreListByType")
	public String selectAllStoreListByType(Store store,HttpServletRequest request, HttpServletResponse response, Model model) {
		List<StoreArea> saList=new ArrayList<>();
		for(Area a:systemService.findArea()) {
			StoreArea sa=new StoreArea();
			sa.setId(a.getId());
			sa.setArea(a.getName());
			sa.setStoreList(systemService.findStore(a.getId()));
			saList.add(sa);
		}
		String userId=request.getParameter("userId");
		YongUser user;
		if(StringUtils.isNotEmpty(userId)) {
			user=yongUserService.get(userId);
			user.setStoreList(systemService.findStoreByUserId(userId));
		}else {
			user=new YongUser();
		}
		model.addAttribute("user", user);
		model.addAttribute("allChecks", saList);
		return "modules/sys/tagStoreselect";
	}

	@RequiresPermissions("sys:commonUser:view")
	@RequestMapping(value = "creditLine")
	public String creditLine(YongUser yongUser, HttpServletRequest request, HttpServletResponse response, Model model) {
		YongUser resultYongUser = yongUserService.get(yongUser.getId());
		Credit credit = creditService.selectByUserId(resultYongUser.getId());
		UserEditHistroy userEditHistroy = new UserEditHistroy();
		userEditHistroy.setUserId(resultYongUser.getId());
		Page<UserEditHistroy> pageUserEditHistroys = userEditHistroyService.selectUserEditHistroyOnCreditByUserId(new Page<UserEditHistroy>(request, response),userEditHistroy);
		model.addAttribute("page", pageUserEditHistroys);
		model.addAttribute("credit", credit);
		model.addAttribute("user", resultYongUser);
		return "modules/sys/yonguser/creditLine";
	}
	
	@RequiresPermissions("sys:commonUser:view")
	@RequestMapping(value = "changeCreditLineSave")
	public String changeCreditLineSave(UserEditHistroy userEditHistroy, HttpServletRequest request, HttpServletResponse response, Model model,RedirectAttributes redirectAttributes) {
		Credit credit = creditService.selectByUserId(userEditHistroy.getUserId());
		if(credit==null){
			credit = new Credit();
			credit.setUserId(userEditHistroy.getUserId());
			credit.setUseMoney(BigDecimal.valueOf(0, 2));
			credit.setRechargeMoney(BigDecimal.valueOf(0, 2));
			credit.setStatus(1);
		}
		credit.setMoney(userEditHistroy.getSum());
		creditService.save(credit);
		userEditHistroy.setMoney(userEditHistroy.getSum());
		userEditHistroy.setMoneyType(0);
		userEditHistroy.setRemainMoney(credit.getMoney().subtract(trimNull(credit.getUseMoney())));
		userEditHistroyService.save(userEditHistroy);
		addMessage(redirectAttributes, "调整额度成功");
		return REDIRECT+ adminPath +LINK2+userEditHistroy.getUserId();
	}
	
	@RequiresPermissions("sys:commonUser:view")
	@RequestMapping(value = "freezeCredit")
	public String freezeCredit(YongUser user, HttpServletRequest request, HttpServletResponse response, Model model,RedirectAttributes redirectAttributes) {
		YongUser resultUser = yongUserService.get(user.getId());
		Credit credit = creditService.selectByUserId(resultUser.getId());
		if(credit==null){
			addMessage(redirectAttributes, TIPS);
			return REDIRECT+ adminPath +LINK2+resultUser.getId();
		}
		credit.setStatus(0);
		creditService.save(credit);
		UserEditHistroy userEditHistroy = new UserEditHistroy();
		userEditHistroy.setUserId(resultUser.getId());
		userEditHistroy.setMoney(credit.getMoney());
		userEditHistroy.setRemainMoney(credit.getMoney().add(trimNull(credit.getRechargeMoney())).subtract(trimNull(credit.getUseMoney())));
		userEditHistroy.setMoneyType(1);
		userEditHistroyService.save(userEditHistroy);
		addMessage(redirectAttributes, "冻结成功");
		return REDIRECT+ adminPath +LINK2+user.getId();
	}
	
	@RequiresPermissions("sys:commonUser:view")
	@RequestMapping(value = "unfreezeCredit")
	public String  unfreezeCredit(YongUser user, HttpServletRequest request, HttpServletResponse response, Model model,RedirectAttributes redirectAttributes) {
		YongUser resultUser = yongUserService.get(user.getId());
		Credit credit = creditService.selectByUserId(resultUser.getId());
		if(credit==null){
			addMessage(redirectAttributes, TIPS);
			return REDIRECT+ adminPath +LINK2+resultUser.getId();
		}
		credit.setStatus(1);
		creditService.save(credit);
		UserEditHistroy userEditHistroy = new UserEditHistroy();
		userEditHistroy.setUserId(resultUser.getId());
		userEditHistroy.setMoney(credit.getMoney());
		userEditHistroy.setRemainMoney(credit.getMoney().subtract(trimNull(credit.getUseMoney())));
		userEditHistroy.setMoneyType(2);
		userEditHistroyService.save(userEditHistroy);
		addMessage(redirectAttributes, "解冻成功");
		return REDIRECT+ adminPath +LINK2+resultUser.getId();
	}
	
	@RequiresPermissions("sys:commonUser:view")
	@RequestMapping(value = "returnMoneySave")
	public String  returnMoneySave(TransactionHistory transactionHistory, HttpServletRequest request, HttpServletResponse response, Model model,RedirectAttributes redirectAttributes) {
		YongUser user = yongUserService.get(transactionHistory.getUserId());
		Credit credit = creditService.selectByUserId(user.getId());
		if(credit==null){
			addMessage(redirectAttributes, TIPS);
			return REDIRECT+ adminPath +LINK3+user.getId();
		}
		credit.setRechargeMoney(trimNull(credit.getRechargeMoney()).add(trimNull(transactionHistory.getMoney())));
		creditService.save(credit);
		String code=CodeUtil.getTransactionHistoryReturnCode();
		transactionHistory.setCode(code);
		transactionHistory.setPayType(0);
		transactionHistory.setMoney(BigDecimal.valueOf(0,2).subtract(trimNull(transactionHistory.getMoney())));
		transactionHistoryService.save(transactionHistory);
		addMessage(redirectAttributes, "还款成功");
		return REDIRECT+ adminPath +LINK3+user.getId();
	}
	
	@RequiresPermissions("sys:commonUser:view")
	@RequestMapping(value = "deductMoneySave")
	public String  deductMoneySave(TransactionHistory transactionHistory, HttpServletRequest request, HttpServletResponse response, Model model,RedirectAttributes redirectAttributes) {
		YongUser user = yongUserService.get(transactionHistory.getUserId());
		Credit credit = creditService.selectByUserId(user.getId());
		if(credit==null){
			addMessage(redirectAttributes, TIPS);
			return REDIRECT+ adminPath +LINK3+user.getId();
		}
		credit.setUseMoney(credit.getUseMoney().add(trimNull(transactionHistory.getMoney())));
		creditService.save(credit);
		String code=CodeUtil.getTransactionHistoryCutCode();
		transactionHistory.setCode(code);
		transactionHistory.setPayType(0);
		transactionHistoryService.save(transactionHistory);
		addMessage(redirectAttributes, "扣款成功");
		return REDIRECT+ adminPath +LINK3+user.getId();
	}
	
	@RequiresPermissions("sys:commonUser:view")
	@RequestMapping(value = "transactionHistoryShow")
	public String transactionHistoryShow(TransactionHistory transactionHistory, HttpServletRequest request, HttpServletResponse response, Model model) {
		YongUser user = yongUserService.get(transactionHistory.getUserId());
		Page<TransactionHistory> pageTransactionHistorys = transactionHistoryService.selectByUserId(new Page<TransactionHistory>(request, response),transactionHistory);
		model.addAttribute("page", pageTransactionHistorys);
		model.addAttribute("user", user);
		model.addAttribute("transactionHistory", transactionHistory);
		return "modules/sys/yonguser/transactionHistoryShow";
	}
	
	/************************************开票信息管理*********************************/
	@RequiresPermissions("sys:commonUser:view")
	@RequestMapping(value = "invoiceInfoList")
	public String invoiceInfoList(InvoiceInfo invoiceInfo, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<InvoiceInfo> page = invoiceInfoService.findPage(new Page<InvoiceInfo>(request, response), invoiceInfo);
		model.addAttribute("page", page);
		model.addAttribute(INVOICEINFO, invoiceInfo);
		return "modules/sys/yonguser/invoiceInfoList";
	}
	
	@RequiresPermissions("sys:commonUser:view")
	@RequestMapping(value = "invoiceInfoDetail")
	public String invoiceInfoDetail(InvoiceInfo invoiceInfo, HttpServletRequest request, HttpServletResponse response, Model model) {
		InvoiceInfo resultInvoiceInfo = invoiceInfoService.get(invoiceInfo.getId());
		model.addAttribute(INVOICEINFO, resultInvoiceInfo);
		return "modules/sys/yonguser/invoiceInfoDetail";
	}
	
	@RequiresPermissions("sys:commonUser:view")
	@RequestMapping(value = "confirmInvoiceInfo")
	public String confirmInvoiceInfo(InvoiceInfo invoiceInfo, HttpServletRequest request, HttpServletResponse response, Model model,RedirectAttributes redirectAttributes) {
		InvoiceInfo resultInvoiceInfo = invoiceInfoService.get(invoiceInfo.getId());
		resultInvoiceInfo.setStatus(1);
		invoiceInfoService.save(resultInvoiceInfo);
		model.addAttribute(INVOICEINFO, resultInvoiceInfo);
		addMessage(redirectAttributes, "开票成功");
		return invoiceInfoList(invoiceInfo, request, response, model);
	}
	
	@RequiresPermissions("sys:commonUser:view")
	@RequestMapping(value = "couldComfirm")
	@ResponseBody
	public String couldComfirm(InvoiceInfo invoiceInfo, HttpServletRequest request, HttpServletResponse response, Model model,RedirectAttributes redirectAttributes) {
		InvoiceInfo resultInvoiceInfo = invoiceInfoService.get(invoiceInfo);
		YongUser user = yongUserService.get(resultInvoiceInfo.getUserId());
		PayHistory byPayCodeAndPayResult;
		if("1".equals(user.getUserType())){
			byPayCodeAndPayResult = payHistoryService.getByPayCodeAndPayResult("1", resultInvoiceInfo.getOrdersCode());
		}else{
			byPayCodeAndPayResult = payHistoryService.getByPayCodeAndPayResult("2", resultInvoiceInfo.getCode());
		}
		if(byPayCodeAndPayResult!=null){
			//如果支付成功
			if("0000".equals(byPayCodeAndPayResult.getOrderPayCode())){
				return "1";
			}else{
				return "0";
			}
		}
		return "0";
	}
	
	
	/**
	 * 如果值为空则赋值0.00
	 * @param BigDecimal
	 * @return BigDecimal
	 */
	public BigDecimal trimNull(BigDecimal bigDecimal){
		return bigDecimal==null?BigDecimal.valueOf(0.00):bigDecimal;
	}
}